import 'isomorphic-fetch';

const myState = {
    count:0,
    count1:1,
    number:10,
    dataGoods:[],
    dataGoodsOri:{},
    dataCate:[],
    dataNews:[],
    dataNewsOri:{},
    dateNews_top:[],
    dataCar:[],
    dataComments:[]
}


function reducer(state=myState,action){
    switch(action.type){
        case "Add":
            console.log(1);
            return Object.assign({},state,{number:state.number +1})
        case "GOODS_LIST_POST":
            return Object.assign({},state,{dataGoods:action.data.rows,dataGoodsOri:action.data})
        case "CATE_LIST_GET":
            return Object.assign({},state,{dataCate:action.data})
        case "SEL_LIST_GOODS" :
            return Object.assign({},state,{dataGoods:action.data.rows,dataGoodsOri:action.data})
        case "GOODS_LIST_POST_FIND":
            return Object.assign({},state,{dataGoods:action.data.rows,dataGoodsOri:action.data})
        case "POST_NEWS_LIST" :
            if(action.data.page==1){
                return Object.assign({},state,{dataNews:action.data.rows,dataNewsOri:action.data,dateNews_top:action.data.rows})
            }else{
                return Object.assign({},state,{dataNews:action.data.rows,dataNewsOri:action.data})
            }
            
        case "POST_NEWS_LIST_TOP" :
            return Object.assign({},state,{dataNews_top:action.data.rows})
        case "SEL_LIST_NEWS" :
            return Object.assign({},state,{dataNews:action.data.rows,dataNewsOri:action.data})
        case "POST_COMMENT_LIST" :
            return Object.assign({},state,{dataComments:action.data.rows})
        case "SUB_COMMENT" :
            return Object.assign({},state,{dataComments:action.data.rows})
        //car--
        case "ADDPRODUCTTOCAR" :
            
            state.dataCar.push(action.data);
            const arr = state.dataCar;
            return Object.assign({},state,{dataCar:arr})
        default:
            return state;
    }
}

export default reducer;